﻿#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using UnityEngine;

namespace Neatly.Native
{
    public class AndroidHelper
    {
        // Android帮助库
        private const string CONST_MAIN_ACTIVITY = "com.unity3d.player.UnityPlayer";
        private const string CONST_FILE_HELPER = "com.neatly.utils.FileHelper";

        private static AndroidJavaClass m_FileHelper;
        private static AndroidJavaClass FileHelper => m_FileHelper ??= new AndroidJavaClass(CONST_FILE_HELPER);
        static AndroidJavaObject m_MainActivity;
        public static AndroidJavaObject MainActivity
        {
            get
            {
                if (m_MainActivity != null) return m_MainActivity;
                AndroidJavaClass jc = new AndroidJavaClass(CONST_MAIN_ACTIVITY);
                m_MainActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
                return m_MainActivity;
            }
        }

        public static byte[] ReadBytes(string fileName)
        {
            return FileHelper.CallStatic<byte[]> ("loadFile", fileName);
        }
        
        public static bool CopyFile(string fileName, string outputPath)
        {
            return FileHelper.CallStatic<bool>("copyFile", fileName, outputPath);
        }
    }
}
